package com.ruoyi.service.score.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.score.entity.CompanyScoreDetailEntity;
import com.ruoyi.service.score.mapper.CompanyScoreDetailMapper;
import com.ruoyi.service.score.service.CompanyScoreDetailService;
import java.util.Optional;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 公司评分明细表 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-14
 */
@Service
public class CompanyScoreDetailServiceImpl extends
    ServiceImpl<CompanyScoreDetailMapper, CompanyScoreDetailEntity>
    implements CompanyScoreDetailService {

  @Override
  public Integer getAvgScore(Long scoreId) {
    return Optional.ofNullable(baseMapper.getAvgScore(scoreId)).orElse(0);
  }

  @Override
  public long countByUserAndProjectId(Long userId, String projectId) {
    return count(queryWrapper().eq(CompanyScoreDetailEntity::getProjectId, projectId)
        .eq(CompanyScoreDetailEntity::getProjectLaborId, userId));
  }

  private LambdaQueryWrapper<CompanyScoreDetailEntity> queryWrapper() {
    return new LambdaQueryWrapper<>();
  }
}
